<%-- 
    Document   : phantrang
    Created on : Jan 6, 2014, 11:37:31 AM
    Author     : Huyen
--%>

<%@page import="bc.entity.Binhluan"%>
<%@page import="businesscard.DAO.BinhluanDAO"%>
<%@page import="bc.entity.Lienhe"%>
<%@page import="businesscard.DAO.LienheDAO"%>
<%@page import="businesscard.DAO.UserDAO"%>
<%@page import="bc.entity.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    User user3 = (User) request.getSession().getAttribute("USER");
    String username1 = user3.getUser();
    UserDAO userDAO1 = new UserDAO();
    User user4 = userDAO1.getUser2(username1);
    int id_user = user4.getIdUser();
    LienheDAO lhDAO = new LienheDAO();
    
%>
<%
    int perpage = 2;
    String p = request.getParameter("page");
    int trang = Integer.parseInt(p);
     int start = (trang - 1) * perpage;
     
      int sotrang;
    int countLH = lhDAO.countLH(id_user);
    if (countLH % perpage != 0) {
        sotrang = countLH / perpage + 1;
    } else {
        sotrang = countLH / perpage;
    }  
     //out.print(p);
       Lienhe[] lh = lhDAO.getLienHeTheoTrang(id_user, start, perpage);
     for (int i = 0; i < lh.length; i++) {

            int id_lienhe = lh[i].getIdLienhe();
            int id_congty = lh[i].getCongty().getIdCongty();
            String congty = lhDAO.getTenCongty(id_congty);
            String ten = lh[i].getTen();
            String tell = lh[i].getSdtcodinh();
            String mobi = lh[i].getSdt();
            String fax = lh[i].getFax();
            String email1 = lh[i].getEmail();
            String diachi = lh[i].getDiachi();
            String huyen = lh[i].getQuanhuyen().getQuanhuyen();
            String tinh = lh[i].getQuanhuyen().getThanhpho().getThanhpho();
            String capbac = lh[i].getCapbac().getCapbac();
            String bophan = lh[i].getBophan().getBophan();
    %>
<div class="lienhe">
        <div class="like"><a href="#">Like</a></div>
        <div class="tencty"><%=congty%></div>
        <div class="tenlh"><%=ten%></div>
        <div class="capbac"><%=capbac%> - bộ phận <%=bophan%></div>
        <div class="tell">Tell:<%=tell%> </div>
        <div class="tell">Mobile:<%=mobi%></div>
        <div class="tell">Fax:<%=fax%></div>
        <div class="tell">Email:<%=email1%></div>
        <div class="add">Add:<%=diachi + ", huyện " + huyen + ", tỉnh " + tinh%></div>
    </div>
    <div class="comment" id="cmtNext<%=i%>">
        <%
            BinhluanDAO A = new BinhluanDAO();
            Binhluan[] B = A.getAllBinhluan(id_lienhe);
            if (B != null) {
                for (int j = 0; j < B.length; j++) {
        %>

        <div class="hinhdaidien">
            <%
                int id = B[j].getUser().getIdUser();
                String link1 = "avatar/" + A.getLinkHinh(id);
            %>
            <image src="<%=link1%>" style="width: 40px; height: 40px;"/>
        </div>
        <div id="usercmt"class="usercmt"><%=B[j].getBinhluan()%></div>


        <%                    }
            }

        %>
    </div>
    
    <div class="binhluan">

        <input type="text" name="binhluan" value=" " placeholder="Viết bình luận..." id="binhluan<%=i%>" />
        <input type="hidden" name="binhluanhide" value="<%=id_lienhe%>" id="txtID"/>
        <input type="submit" value="Bình luận" name="action" onclick="comment('<%=id_lienhe%>', '<%=i%>');"/>   

    </div>
    <%
        }
    %>
<div class="phantrang" style="margin-left:280px;">
    <% 
        String abc=lhDAO.phantrang(sotrang, trang); 
        out.print(abc);
    %>
    </div>
  